<!DOCTYPE html>
<html lang="en">

<head>
	<title>夸父追日</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<style>
		html,
		body {
			width: 100%;
			height: 100%;
		}

		body {
			background-color: #ffffff;
			margin: 0;
			overflow: hidden;
			font-family: arial;
		}

		#blocker {

			position: absolute;

			width: 100%;
			height: 100%;

			background-color: rgba(0, 0, 0, 0.5);

		}

		#instructions {

			width: 100%;
			height: 100%;

			display: -webkit-box;
			display: -moz-box;
			display: box;

			-webkit-box-orient: horizontal;
			-moz-box-orient: horizontal;
			box-orient: horizontal;

			-webkit-box-pack: center;
			-moz-box-pack: center;
			box-pack: center;

			-webkit-box-align: center;
			-moz-box-align: center;
			box-align: center;

			color: #ffffff;
			text-align: center;

			cursor: pointer;

		}
	</style>
</head>

<body>

	<script src="js/three.js"></script>
	<script src="js/controls/OrbitControls.js"></script>
	<script src="js/controls/PointerLockControls.js"></script>
	<script src="js/renderers/Projector.js"></script>
	<script src="js/renderers/CanvasRenderer.js"></script>
	<script src="js/objects/Sky.js"></script>

	<script src="js/WebGL.js"></script>

	<div id="blocker">

		<div id="instructions">
			<span style="font-size:80px">夸父追日</span>
			<br />
			<a style="font-size:20px">
				&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				------日落之前完成你的任务
			</a>
			<br />
			<br />
			<br />
			<br />
			<span style="font-size:35px">点击继续游戏</span>
			<br />
			<br />
			<br />
			<span style="font-size:20px">任务目标：在日落之前搜集到所有雪球。&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>
			<br />
			<br />
			<span style="font-size:20px">&nbsp&nbsp&nbsp道具：时间魔法锥 —— 可以延缓日落的时间！</span>
			<br />

			<pre>
			<br />
			W，A，S，D —— 移动
			<br />
			鼠标移动 —— 视角旋转
			<br />
			空格 —— 跳跃
			<br />
			Shift(按住) —— 加速模式
			<br />
			CapsLock(切换) —— 蹲下/站立
			<br />
			<br />
			
			
			
		</div>

	</div>

	<script>
		/**
		 * 页面载入后进入游戏的编辑状态。
		 * 按住左键拖动可旋转视角。
		 * 按住右键拖动可平移视角。
		 * 单击左键可以添加游戏模块。
		 * 按住Shift点击游戏模块会删除点击的模块。
		 * 
		 * 一共有三种模块可选择，分别为方块墙，雪球，时间魔法锥。
		 * 键盘数字1：切换当前游戏模块为方块墙，拥有碰撞检测。
		 * 键盘数字2：切换当前游戏模块为雪球，游戏的任务目标。
		 * 键盘数字3：切换当前游戏模块为时间魔法锥，可以延缓日落时间。
		 * 键盘数字6：锁定鼠标，用鼠标某些情况下不小心unlock时的bug。
		 * 键盘数字7：删除保存的模块。
		 * 键盘数字8：载入保存的模块。
		 * 键盘数字9：保存当前场景内的模块。
		 * 
		 * 键盘数字0：切换为游戏模式：
		 * 
		 * 鼠标移动：视角旋转。
		 * WASD：移动。
		 * 空格键：跳跃。
		 * Shift键（按住）：加速。
		 * CapsLock（切换）：蹲下/起立。
		 * 
		 * 雪球和魔法锥可以被踩掉，从而发挥其作用。
		 * 
		*/
		var container;
		var camera, scene, renderer;
		var controls, runControls;
		var plane;
		var presentId = 1;

		var mouse, raycaster2;
		var raycaster_down, raycaster_up, raycaster_left, raycaster_right, raycaster_front, raycaster_back;
		var isShiftDown = false;
		var isCtrl = false; //下蹲状态
		var running = false;
		var runLook = new THREE.Vector3(0,0,0);
		var tall = 50;
		var moveForward = false;
		var moveBackward = false;
		var moveLeft = false;
		var moveRight = false;

		var canJump = false;
		var canFront = false;
		var canBack = false;
		var canLeft = false;
		var canRight = false;

		var ballNum = 0; //游戏雪球数量
		var additon = 0; //隐藏游戏模式
		var prevTime = performance.now();
		var velocity = new THREE.Vector3();
		var direction = new THREE.Vector3();
		var vertex = new THREE.Vector3();
		var sun = new THREE.Vector3();
		var sunTime = 0; //太阳轨迹的绝对时间
		var sunSpeed = 1000;

		var status0 = true;
		var status1 = true;
		var status2 = true;
		var status3 = true;

		//模型形状
		var cubeGeometry = new THREE.BoxBufferGeometry(50, 50, 50);
		//模型材料
		//默认材料

		//草地材料
		var grassMaterial = new THREE.MeshPhongMaterial({ color: 0xfafafa, specular: 0xaca165, shininess: 40, shading: THREE.FlatShading, reflectivity: 0.2 });
		var texture = new THREE.TextureLoader().load('textures/snowground1.jpg');
		texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		texture.repeat.set(10, 10);
		texture.anisotropy = 16;
		grassMaterial.bumpMap = texture;
		grassMaterial.bumpScale = 4;
		var texture = new THREE.TextureLoader().load('textures/snowground1.jpg');
		texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		texture.repeat.set(10, 10);
		texture.anisotropy = 16;
		grassMaterial.map = texture;

		//box材料
		var boxMaterial = new THREE.MeshPhongMaterial({ color: 0xfbf5f3, specular: 0x504f4e, shininess: 5, shading: THREE.FlatShading, reflectivity: 0.15 });
		var texture = new THREE.TextureLoader().load('textures/ice5.jpg');
		texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		texture.repeat.set(1, 1);
		texture.anisotropy = 16;
		boxMaterial.map = texture;

		// sphere
		var ballGeo = new THREE.SphereBufferGeometry(25, 32, 16);
		var ballMaterial = new THREE.MeshLambertMaterial();
		texture = new THREE.TextureLoader().load('textures/snowground1.jpg');
		texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
		texture.repeat.set(1, 1);
		texture.anisotropy = 16;
		ballMaterial.map = texture;




		// //背景盒子
		// var path = "textures/cube/skyboxsun25deg/";//设置路径
		// var directions  = ["px", "nx", "py", "ny", "pz", "nz"];//获取对象
		// var format = ".jpg";//格式
		// //创建盒子，并设置盒子的大小为( 5000, 5000, 5000 )
		// var skyGeometry = new THREE.BoxGeometry( 5000, 5000, 5000 );
		// //设置盒子材质
		// var materialArray = [];
		// for (var i = 0; i < 6; i++)
		// 	materialArray.push( new THREE.MeshBasicMaterial({
		// 		map: THREE.ImageUtils.loadTexture( path + directions[i] + format ),//将图片纹理贴上
		// 		side: THREE.BackSide/*镜像翻转，如果设置镜像翻转，那么只会看到黑漆漆的一片，因为你身处在盒子的内部，所以一定要设置镜像翻转。*/
		// 	}));
		// var skyMaterial = new THREE.MeshFaceMaterial( materialArray );
		//平行光，有投影
		var light = new THREE.PointLight(0xbdbdbd, 0.8);
		light.position.set(50, 200, 100);
		light.position.multiplyScalar(1.3);
		light.castShadow = true;
		light.shadow.mapSize.width = 1024;
		light.shadow.mapSize.height = 1024;
		var d = 3000;
		light.shadow.camera.left = - d;
		light.shadow.camera.right = d;
		light.shadow.camera.top = d;
		light.shadow.camera.bottom = - d;
		light.shadow.camera.far = 10000;

		texture = new THREE.TextureLoader().load('textures/sprites/snowflake2.png');
		pointsMaterial = new THREE.PointsMaterial({
			color: 0x888888,
			size: 5,
			transparent: true,
			opacity: 0.9,
			map: texture,
			blending: THREE.AdditiveBlending,
			sizeAttenuation: true,
			depthTest: true
		});



		var sky = new THREE.Sky();
		sky.scale.setScalar(10000);


		var uniforms = sky.material.uniforms;

		uniforms.turbidity.value = 2.5;
		uniforms.rayleigh.value = 1.8;
		uniforms.luminance.value = 1;
		uniforms.mieCoefficient.value = 0.01;
		uniforms.mieDirectionalG.value = 0.65;

		var parameters = {
			distance: 400,
			inclination: 0.49,
			azimuth: 0.205
		};

		function updateSun(dertaTime) {
			sunTime += dertaTime;
			var theta = Math.PI * (parameters.inclination - 0.5);
			var phi = 2 * Math.PI * (parameters.azimuth - 0.5);
			theta -= sunTime * Math.PI * 2 / sunSpeed;
			phi -= sunTime * Math.PI / sunSpeed;

			sun.x = parameters.distance * Math.cos(phi);
			sun.y = parameters.distance * Math.sin(phi) * Math.sin(theta);
			sun.z = parameters.distance * Math.sin(phi) * Math.cos(theta);

			sky.material.uniforms.sunPosition.value = sun;
			light.position.x = sky.material.uniforms.sunPosition.value.x * 13;
			light.position.y = sky.material.uniforms.sunPosition.value.y * 13;
			light.position.z = sky.material.uniforms.sunPosition.value.z * 13;
		}



		var objects = [];
		var newObj = [];

		init();
		animate();

		function init() {

			container = document.createElement('div');
			document.body.appendChild(container);

			var info = document.createElement('div');
			info.style.position = 'absolute';
			info.style.top = '10px';
			info.style.width = '100%';
			info.style.textAlign = 'center';

			container.appendChild(info);

			//相机种类
			camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 20000);
			camera.position.set(250, 400, 650);

			runCamera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 3000);
			//runCamera.renderTarget.texture.minFilter = THREE.LinearMipMapLinearFilter;
			//场景
			scene = new THREE.Scene();
			scene.background = new THREE.Color(0xcce0ff);
			scene.fog = new THREE.FogExp2(0xeeeeee, 0.0006);



			//相机控制
			controls = new THREE.OrbitControls(camera);
			controls.maxPolarAngle = Math.PI * 0.5;
			controls.minDistance = 10;
			controls.maxDistance = 10000;
			controls.rotateSpeed = 1;

			runControls = new THREE.PointerLockControls(runCamera);
			runControls.maxPolarAngle = Math.PI * 0.5;
			runControls.minDistance = 10;
			runControls.maxDistance = 10000;
			runControls.rotateSpeed = 1;

			var blocker = document.getElementById('blocker');
			var instructions = document.getElementById('instructions');


			instructions.style.display = 'none';
			blocker.style.display = 'none';

			instructions.addEventListener('click', function (event) {
				instructions.style.display = 'none';
				blocker.style.display = 'none';
				runControls.lock();

			}, false);
			scene.add(runControls.getObject());

			//网格地面
			//var gridHelper = new THREE.GridHelper( 10000, 200 );
			//scene.add( gridHelper );

			//用于计算当前鼠标所指的对象
			raycaster2 = new THREE.Raycaster();
			mouse = new THREE.Vector2();
			raycaster_down = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(0, -1, 0), 0, tall);
			raycaster_up = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(0, 1, 0), 0, 10);
			raycaster_front = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(0, 0, 1), 0, 10);
			raycaster_back = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(0, 0, -1), 0, 10);
			raycaster_left = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(1, 0, 0), 0, 10);
			raycaster_right = new THREE.Raycaster(new THREE.Vector3(), new THREE.Vector3(-1, 0, 0), 0, 10);

			//矩形地面
			var geometry = new THREE.PlaneGeometry(10000, 10000);
			geometry.rotateX(- Math.PI / 2);

			//由形状和材质创建出地面		
			plane = new THREE.Mesh(geometry, grassMaterial);
			plane.receiveShadow = true;
			scene.add(plane);
			objects.push(plane);

			// var skyBox = new THREE.Mesh( skyGeometry, skyMaterial );//创建一个完整的天空盒，填入几何模型和材质的参数
			// scene.add( skyBox );//在场景中加入天空盒
			// objects.push(skyBox);

			//环境光，无投影
			var ambientLight = new THREE.AmbientLight(0x606060);
			scene.add(ambientLight);

			scene.add(light);

			renderer = new THREE.WebGLRenderer({ antialias: true });
			//像素比率(画质)
			renderer.setPixelRatio( window.devicePixelRatio ); //适应其他设备
			// renderer.setPixelRatio(0.7);
			renderer.setSize(window.innerWidth, window.innerHeight);
			container.appendChild(renderer.domElement);
			renderer.gammaInput = true;
			renderer.gammaOutput = true;
			renderer.shadowMap.enabled = true;

			// Skybox
			scene.add(sky);
			snow = new THREE.Geometry();
			let range = 10000;
			let snowNum = 50000;
			for (let i = 0; i < snowNum; i++) {
				let vertice = new THREE.Vector3(
					Math.random() * range - range / 2,
					Math.random() * range * 1,
					Math.random() * range - range / 2);
				/* 纵向移动速度 */
				vertice.velocityY = 10 * (0.1 + Math.random() / 5);
				/* 横向移动速度 */
				vertice.velocityX = 10 * ((Math.random() - 0.5) / 3);
				/* 将顶点加入几何 */
				snow.vertices.push(vertice);
			}
			snow.center();
			points = new THREE.Points(snow, pointsMaterial);
			scene.add(points);


			updateSun(1);

			document.addEventListener('mousedown', onDocumentMouseDown, false);
			document.addEventListener('keydown', onDocumentKeyDown, false);
			document.addEventListener('keyup', onDocumentKeyUp, false);

			//

			window.addEventListener('resize', onWindowResize, false);
			runControls.addEventListener('unlock', function () {
				if (running) {
					blocker.style.display = 'block';
					instructions.style.display = '';
				}

			});
		}
		function snowUpdate() {
			let vertices = points.geometry.vertices;
			vertices.forEach(function (v) {
				v.y = v.y - (v.velocityY);
				v.x = v.x - (v.velocityX);
				if (v.y <= 0) v.y = 10000;
				if (v.x <= -5000 || v.x >= 5000) v.velocityX = v.velocityX * -1;

			});
			/* 顶点变动之后需要更新，否则无法实现雨滴特效 */
			points.geometry.verticesNeedUpdate = true;
		}
		function onWindowResize() {

			if (running == false) {
				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();
			} else {
				runCamera.aspect = window.innerWidth / window.innerHeight;
				runCamera.updateProjectionMatrix();
			}


			renderer.setSize(window.innerWidth, window.innerHeight);

			render();

		}

		function onDocumentMouseDown(event) {

			event.preventDefault();
			//在标准坐标中计算鼠标的坐标
			mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
			mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;

			// update the picking ray with the camera and mouse position
			raycaster2.setFromCamera(mouse, camera);

			// calculate objects intersecting the picking ray
			var intersects = raycaster2.intersectObjects(objects);

			if (intersects.length > 0) {

				var intersect = intersects[0];

				if (isShiftDown) {

					if (intersect.object != plane) {

						scene.remove(intersect.object);

						objects.splice(objects.indexOf(intersect.object), 1);
						newObj.splice(objects.indexOf(intersect.object), 1);
						if (intersect.object.name == '2') ballNum--; //雪球数量-1

					}

				} else {
					var voxel = getVoxel(presentId);
					voxel.position.copy(intersect.point).add(intersect.face.normal);
					voxel.position.divideScalar(50).floor().multiplyScalar(50).addScalar(25);
					scene.add(voxel);
					objects.push(voxel);
					newObj.push(voxel);

				}

				render();

			}

		}

		function getVoxel(id) {
			var voxel;
			if (id == 1) {
				voxel = new THREE.Mesh(cubeGeometry, boxMaterial);
				voxel.castShadow = false;
				voxel.receiveShadow = true;
				voxel.name = '1';
			}
			if (id == 2) {
				voxel = new THREE.Mesh(ballGeo, ballMaterial);
				voxel.castShadow = true;
				voxel.receiveShadow = true;
				voxel.name = '2';
				ballNum++;
			}
			if (id == 3) {
				var geometry = new THREE.CylinderBufferGeometry(0, 12, 25, 100, 0);
				var material = new THREE.MeshPhongMaterial({ color: 0xffffff, flatShading: true });
				let texture = new THREE.TextureLoader().load('textures/ice4.jpg');
				material.map = texture;
				voxel = new THREE.Mesh(geometry, material);
				voxel.name = '3';
			}
			return voxel;
		}

		function onDocumentKeyDown(event) {

			switch (event.keyCode) {
				//shift
				case 16: isShiftDown = true; break;
				//Ctrl
				case 20:
					isCtrl = (isCtrl) ? false : true;
					if (!isCtrl) runControls.getObject().position.y += tall;
					break;
				//大键盘0
				case 48:
					if (running == false) { //之前是编辑状态
						running = true;
						blocker.style.display = 'block';
						instructions.style.display = '';
						presentId = 4;
						alert('本次游戏一共有' + ballNum.toString() + '个雪球！');
					} else { //之前是运行状态
						running = false;
						runControls.unlock();
						reload();

					}

					break;
				case 49: presentId = 1; break;
				case 50: presentId = 2; break;
				case 51: presentId = 3; break;
				case 52: presentId = 4; break;
				case 53:
					presentId = 5;
					break;
				case 54:
					presentId = 6;
					runControls.lock();
					break;
				case 55: objDelete(); break;
				case 56: objLoad(); break;
				case 57: objSave(); break;
				//w
				case 87: moveForward = true; break;
				//a
				case 65: moveLeft = true; break;
				//s
				case 83: moveBackward = true; break;
				//d
				case 68: moveRight = true; break;
				//space
				case 32:
					if (canJump == true) velocity.y += 350;
					canJump = false;
					break;
			}

		}

		function onDocumentKeyUp(event) {

			switch (event.keyCode) {
				//L-shift
				case 16: isShiftDown = false; break;
				//w
				case 87: moveForward = false; break;
				//a
				case 65: moveLeft = false; break;
				//s
				case 83: moveBackward = false; break;
				//d
				case 68: moveRight = false; break;


			}
		}

		function touchCheck() {
			
			raycaster_up.ray.origin.copy(runControls.getObject().position);
			var intersections = raycaster_up.intersectObjects(objects);
			canUp = !(intersections.length > 0);
			
			runControls.getDirection(runLook);

			raycaster_front.ray.origin.copy(runControls.getObject().position);
			raycaster_front.ray.direction.x = runLook.x;
			raycaster_front.ray.direction.y = 0;
			raycaster_front.ray.direction.z = runLook.z;
			var intersections = raycaster_front.intersectObjects(objects);
			canFront = !(intersections.length > 0);

			raycaster_back.ray.origin.copy(runControls.getObject().position);
			raycaster_back.ray.direction.x = runLook.x*(-1);
			raycaster_back.ray.direction.y = 0;
			raycaster_back.ray.direction.z = runLook.z*(-1);
			var intersections = raycaster_back.intersectObjects(objects);
			canBack = !(intersections.length > 0);

			raycaster_left.ray.origin.copy(runControls.getObject().position);
			raycaster_left.ray.direction.x = runLook.z;
			raycaster_left.ray.direction.y = 0;
			raycaster_left.ray.direction.z = runLook.x*(-1);
			var intersections = raycaster_left.intersectObjects(objects);
			canLeft = !(intersections.length > 0);

			raycaster_right.ray.origin.copy(runControls.getObject().position);
			raycaster_right.ray.direction.x = runLook.z*(-1);
			raycaster_right.ray.direction.y = 0;
			raycaster_right.ray.direction.z = runLook.x;
			var intersections = raycaster_right.intersectObjects(objects);
			canRight = !(intersections.length > 0);


			if (canUp == false) {
				velocity.y = Math.min(0, velocity.y);
			}
			if (canFront == false) {
				velocity.z = Math.max(0, velocity.z);
				direction.z = Math.max(0, direction.z);
			}
			if (canBack == false) {
				velocity.z = Math.min(0, velocity.z);
				direction.z = Math.min(0, direction.z);
			}
			if (canLeft == false) {
				velocity.x = Math.max(0, velocity.x);
				direction.x = Math.max(0, direction.x);
			}
			if (canRight == false) {
				velocity.x = Math.min(0, velocity.x);
				direction.x = Math.min(0, direction.x);
			}
		}
		function objSave() {
			console.log('保存中......');
			var saveJson = {};
			saveJson.ids = [];
			saveJson.positions = [];
			saveJson.length = 0;
			for (var i = 0; i < newObj.length; i++) {
				saveJson.ids.push(newObj[i].name);
				saveJson.positions.push(newObj[i].position);
				saveJson.length++;
			}
			localStorage.setItem('scene', JSON.stringify(saveJson));
			console.log('保存成功！');
			alert('保存成功！');
		}

		function objLoad() {
			console.log('加载中......');
			let jsonString = localStorage.getItem('scene');

			if (jsonString) {
				// 将 jsonString 字符串转换为 json 对象
				let saveJson = JSON.parse(jsonString);
				console.log(saveJson);
				for (var i = 0; i < saveJson.length; i++) {
					var voxel = getVoxel(saveJson.ids[i]);
					voxel.position.copy(saveJson.positions[i]);
					scene.add(voxel);
					objects.push(voxel);
					newObj.push(voxel);
				}
				render();
			}
			console.log('加载成功！');
			alert('加载成功！');
		}

		function objDelete() {
			console.log('删除中......');
			localStorage.removeItem('scene');
			console.log('删除成功！');
			alert('删除成功！');
		}

		function render() {
			if (running == false) {
				renderer.render(scene, camera);
			} else {
				renderer.render(scene, runCamera);
			}
		}

		function reload() {
			addtion = 0; //关闭隐藏模式
			sunSpeed = 1000; //恢复太阳速度
			sunTime = 0; //重置太阳轨迹时间
			status0 = true;
			status1 = true;
			status2 = true;
			status3 = true;

		}
		function animate() {

			requestAnimationFrame(animate);
			if (!running) controls.update();
			var time = performance.now();
			var delta = (time - prevTime) / 1000;
			if (running) {
				updateSun(delta);
				//runControls.update();
				if (ballNum == 0) {
					if (additon == 1) {
						if (status3 == true) {
							alert('不要被任务目标蒙蔽了双眼，一味地完成被指定的事情。探索一下，原来你做到了比原目标更多的事情！恭喜你完成了隐藏的最最最终任务！请“赶快”利用这剩余的时光吧！');
							sunSpeed = 500;
							status3 = false;
						}

					} else {
						if (status1 == true) {
							alert('恭喜您完成了最终任务！！请尽情的享用这剩余的时光吧！！');
							status1 = false;
						}

					}
				}

				if (sun.y <= 0) {
					if (status0 == true) {
						alert('很遗憾，太阳已落下，您的时间已用尽......');
						status0 = false;
					}

				}

				if (sunTime < 0) {
					if (status2 == true) {
						alert('恭喜您完成隐藏的最最终任务，成功地将时间重置。通关的方式不止一种，在日落之前你还可以做很多事情！请愉悦的享用剩余的时间吧！');
						additon = 1;
						status2 = false;
					}

				}

				tall = (isCtrl) ? 25 : 50;
				raycaster_down.far = tall;
				raycaster_down.ray.origin.copy(runControls.getObject().position);

				var intersections = raycaster_down.intersectObjects(objects);
				var onObject = intersections.length > 0;

				//摩擦力
				velocity.x -= velocity.x * 2.0 * delta;
				velocity.z -= velocity.z * 2.0 * delta;
				//重力
				velocity.y -= 9.8 * 100.0 * delta; // 100.0 = mass

				// touchCheck();
				direction.z = Number(moveForward) - Number(moveBackward);
				direction.x = Number(moveLeft) - Number(moveRight);
				direction.normalize(); // this ensures consistent movements in all directions
				var upspeed = isShiftDown ? 800.0 : 400.0;
				if ((moveForward) || (moveBackward)) velocity.z -= direction.z * upspeed * delta;
				if ((moveLeft) || (moveRight)) velocity.x -= direction.x * upspeed * delta;

				if (onObject === true) {
					if (intersections[0].object.name == '3') { //魔法锥
						scene.remove(intersections[0].object);
						objects.splice(objects.indexOf(intersections[0].object), 1);
						newObj.splice(newObj.indexOf(intersections[0].object), 1);
						sunTime -= 10;
					}
					if (intersections[0].object.name == '2') { //雪球
						scene.remove(intersections[0].object);
						objects.splice(objects.indexOf(intersections[0].object), 1);
						newObj.splice(newObj.indexOf(intersections[0].object), 1);
						ballNum--;
					}
					velocity.y = Math.max(0, velocity.y);
					canJump = true;

				}
				touchCheck();
				// raycaster_X = new THREE.Raycaster( myPosition, touch, 0, 10 );
				// // // console.log(raycaster_X);
				// intersections = raycaster_X.intersectObjects( objects );
				// // // console.log(intersections.length);
				// var canMove_X = !(intersections.length > 0);
				// if(canMove_X == false){
				// 	console.log(intersections[0]);
				// 	velocity.x = 0;
				// 	velocity.z = 0;
				// }

				runControls.getObject().translateX(velocity.x * delta);
				runControls.getObject().translateY(velocity.y * delta);
				runControls.getObject().translateZ(velocity.z * delta);

				if (runControls.getObject().position.y < tall) {
					velocity.y = 0;
					runControls.getObject().position.y = tall;
					canJump = true;
				}

				prevTime = time;

			}
			snowUpdate();
			render();

		}

	</script>

</body>

</html>